package com.iwish.server.storage.DAO;

import java.util.List;

import org.apache.log4j.Logger;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.iwish.server.storage.MongoPool;
import com.iwish.server.storage.DAO.trash.UserDAO;
import com.iwish.server.storage.util.ConfigHelper;
import com.mongodb.Mongo;

public class MongoDAO {
	static MongoPool mgpool = new MongoPool(ConfigHelper.MONGO_HOST);
	static Logger logger = Logger.getLogger(MongoDAO.class);

	static MongoPool getMongoPool(){

		// TODO Auto-generated method stub
		
		return mgpool;
	}

	public static Object execute(Class c,SQLCommand command) {
	
		Mongo mon = (Mongo)mgpool.getResource();
		Morphia mp = new Morphia();
		mp.map(c);
		Datastore ds = mp.createDatastore(mon, ConfigHelper.DBNAME);
		ds.ensureIndexes();
		
		mgpool.returnResource(mon);
		command.print();
		return command.sql(c,ds);
	}
}
